﻿Imports System.IO

Public Class Form1

    'dilosi metavliton
    Dim myStream As FileStream = Nothing
    Private StringToPrint As String

    Private Sub OpenFile1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFile1ToolStripMenuItem.Click
        Dim FilePath As String

        'Emfanisi plaisiou dialogou Open
        OpenFileDialog1.Filter = "Text Files (.txt)|*.txt"
        OpenFileDialog1.ShowDialog()

        If OpenFileDialog1.FileName <> "" Then 'an den einai keno
            FilePath = OpenFileDialog1.FileName 'anoigei to arxeio

            Try
                'revma eisodou pros to RichTextBox1
                Dim MyFileStream As New FileStream(FilePath, FileMode.Open)
                RichTextBox1.LoadFile(MyFileStream, RichTextBoxStreamType.PlainText)
                MyFileStream.Close()

                'ektyposi xaraktiron sto RTB1
                StringToPrint = RichTextBox1.Text

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If

    End Sub


    Private Sub OpenFile2ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFile2ToolStripMenuItem.Click
        Dim myStream2 As FileStream = Nothing
        Dim openFileDialog1 As New OpenFileDialog()
        Dim FilePath2 As String

        openFileDialog1.Filter = "Text Files (.txt)|*.txt"
        openFileDialog1.ShowDialog()

        If openFileDialog1.FileName <> "" Then
            FilePath2 = openFileDialog1.FileName

            Try

                Dim MyFileStream As New FileStream(FilePath2, FileMode.Open)
                RichTextBox2.LoadFile(MyFileStream, RichTextBoxStreamType.PlainText)
                MyFileStream.Close()

                StringToPrint = RichTextBox2.Text

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If



    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'sigkrinei an to RTB1 einai idio me to RTB2
        If RichTextBox2.Text = RichTextBox1.Text Then
            MessageBox.Show("Files are same")
        Else
            MessageBox.Show("Files are different")
        End If

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        'Form2.MdiParent = Me 'gia na emfanizetai
        'entos twn plaisiwn tou menu
        Form2.Show()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class